package engine.newUi
{
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ObjectData;
	import engine.flag.ResourcesPath;
	import engine.net.datatype.WString;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.ui.AlertUI;
	
	import flash.events.MouseEvent;
	
	import newx.com.config.StaticIni;
	import newx.com.control.window.NxWindowEvent;
	/**
	 *宠物详细属性界面 （已废弃） 
	 * @author liuel
	 * 
	 */
	public class PetPropertyLogic
	{
		private static var _self :PetPropertyLogic;
		private var _ui:PetPropertyUI;
		private var _bindMang:BindManage;
		private var _bindInde:int =-1;
		private var _bindObj:Object;
		private var _bindFuncArr:Array //绑定属性的执行函数数组
		private var _bindPropertyArr:Array //绑定的属性数组
		private var _model:ModelLocator;
		private var _bingdFlagArr:Array=[];
		/**
		 *传入数据 
		 */		
		private var _mainObj:*;
		public static function getIntance():PetPropertyLogic
		{
			if(_self ==null)
			{
				_self =new PetPropertyLogic();
			}
			return _self;
		}
		public function PetPropertyLogic()
		{
		}
		public function Init():void
		{
			_model	= ModelLocator.getInstance();
			_ui	= PetPropertyUI.getInstance();
			_bindMang =BindManage.getInstance();
			_bindFuncArr=["model1","leve1","name1","clue","maxHPAdd1","staAdd1","strAdd1","ingAdd1","phyDamageAdd1","magDamageAdd1","phyHitProbAdd1","phyDodgeProbAdd1","phyVaProbAdd1","phyVaDefProbAdd1","phyWardProbAdd1","dePhyWardProbAdd1"];
			_bindPropertyArr=["Model","Level","PetName","Clue","PetMaxHPAdd","PetStaAdd","PetStrAdd","PetIngAdd","PetPhyDamageAdd","PetMagDamageAdd","PetPhyHitProbAdd","PetPhyDodgeProbAdd","PetPhyVaProbAdd","PetPhyVaDefProbAdd","PetPhyWardProbAdd","PetDePhyWardProbAdd"];
		}
		public function BeforeShow():void
		{
			addEvent();
			bind();
			
		}
		private function addEvent():void
		{
			_ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClose);
			_ui.changeName.addEventListener(MouseEvent.CLICK,onChange);
		}
		private function removeEvent():void
		{
			_ui.windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,onClose);
			_ui.changeName.removeEventListener(MouseEvent.CLICK,onChange);
		}
		public function AfterHide():void
		{
			deletBind();
			removeEvent();
			_bindObj=null;
		}
		private function onClose(e:NxWindowEvent):void
		{
			_ui.hide();
		}
		private function onChange(e:MouseEvent):void
		{
			AlertUI.showAlert(StaticIni.getSwfLangStr("改名"),"",AlertUI.OK|AlertUI.CANCEL,onChangeNameBack,null,true);
		}
	
		private function onChangeNameBack(type:int, str:String, clickData:*):void
		{
			if(AlertUI.OK == type)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CHANGE_NAME,int(_bindObj.GetProperties("ConfigID")),new WString(str));
			}
		}
		/**
		 *打开任务宠物详细属性的接口 
		 * @param date
		 * 
		 */		
		public function set PetProperty(date:*):void
		{
			if(date == null)return;
			_mainObj=date;
			if(_ui.created== false)
			{
				_ui.showOrHide();
			}
			else
			{
				bind();
			}
		
		}
		private function bind():void
		{
			if(_bindObj ==null || (_bindObj !=null && _bindObj.GetProperties("ConfigID")!=_mainObj.GetProperties("ConfigID")))
			{
				restbind();
			}
		
		}
		/**
		 * 重新绑定 
		 * @param viewobj
		 * 
		 */		
		public function restbind():void
		{
			deletBind();
			//重绑
			bindProperty(_mainObj);
		}
		/**
		 *解绑 
		 * 
		 */		
		private function deletBind():void
		{
			if(_bindObj!=null)
			{
				//解绑
				for(var i:int=0;i<_bindFuncArr.length;i++)
				{
					if(_bindObj.CheckProperties(_bindPropertyArr[i]))
					{
						_bingdFlagArr[i]=_bindMang.UnbindProp(_bindObj as ObjectData,_bindPropertyArr[i],_bingdFlagArr[i]);
					}
				}
			}
		}
		private function setBtnState():void
		{
			if(PetLoic.getInstance().currPetisSelf)
			{	
				_ui.changeName.enabled=true;
			}
			else
			{
				_ui.changeName.enabled=false;
			}
		}
		/**
		 * 绑定属性 
		 * @param viewobj
		 * 
		 */		
		private function  bindProperty(viewobj:*):void
		{
			_bindObj=viewobj;
			for(var i:int=0;i<_bindFuncArr.length;i++)
			{
				if(viewobj.CheckProperties(_bindPropertyArr[i]))
				{
					_bingdFlagArr[i]=_bindMang.BindProp(viewobj as ObjectData,_bindPropertyArr[i],this,_bindFuncArr[i]);
				}
			}
			var obj:Object=StaticIni.getIniObj(_bindObj.GetProperties("ConfigID"));
			if(obj !=null)
			{
				adept1=obj["Trait"];
				description=obj["description"];
			}
				
		}
		/**
		 *擅长 
		 * @param str
		 * 
		 */		
		public function set description(str:String):void
		{
			if(str==null)
			{
				_ui.nxtext.htmlText="";
				return;
			}
			_ui.nxtext.htmlText =StaticIni.getSwfLangStr(str);
		}
		public function set clue(value:int):void
		{
			if(value ==31)  // 11111 是自己的
			{
				_ui.changeName.enabled=true;
			}
			else
			{
				_ui.changeName.enabled=false;
			}
		}
		/**
		 *设置宠物头像 
		 * 
		 */		
		public function set model1(val:int):void
		{	
		
			var model:int=PetLoic.getInstance().currPetisSelf?val:49330100;
		
			_ui.picMC.source = ResourcesPath.getHeadPic(model);
		
		}
		/**名字**/
		public function set name1(name:String):void
		{
			_ui.nameLabel.htmlText =name;
		}
		/**等级**/
		public function set leve1(val:int):void
		{
			_ui.lvLabel.htmlText =val.toString();
		}
		/**擅长**/
		public function set adept1(str:String):void
		{
			_ui.adeptLabel.htmlText = StaticIni.getSwfLangStr(str);
		}
		/**生命**/
		public function set maxHPAdd1(val:Number):void
		{
			_ui.labbel1.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_01",[val.toFixed(0)]);
		}
		/**体魄**/
		public function set staAdd1(val:Number):void
		{
			_ui.labbel2.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_19",[val.toFixed(0)]);
		}
		/**外功**/
		public function set strAdd1(val:Number):void
		{
			_ui.labbel3.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_17",[val.toFixed(0)]);
		}
		/**内功**/
		public function set ingAdd1(val:Number):void
		{
			_ui.labbel4.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_18",[val.toFixed(0)]);
		}
		/**普攻**/
		public function set phyDamageAdd1(val:Number):void
		{
			_ui.labbel5.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_02",[val.toFixed(0)]);
		}
		/**绝攻**/
		public function set magDamageAdd1(val:Number):void
		{
			_ui.labbel6.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_04",[val.toFixed(0)]);
		}
		/**命中**/
		public function set phyHitProbAdd1(val:Number):void
		{
			_ui.labbel7.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_07",[val.toFixed(2)]);
		}
		/**闪避**/
		public function set phyDodgeProbAdd1(val:Number):void
		{
			_ui.labbel8.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_06",[val.toFixed(2)]);
		}
		/**暴击**/		
		public function set phyVaProbAdd1(val:Number):void
		{
			_ui.labbel9.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_12",[val.toFixed(2)]);
		}
		/**韧性**/
		public function set phyVaDefProbAdd1(val:Number):void
		{
			_ui.labbel10.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_13",[val.toFixed(2)]);
		}
		/**抵挡**/
		public function set phyWardProbAdd1(val:Number):void
		{
			_ui.labbel11.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_08",[val.toFixed(2)]);
		}
		/**破击**/
		public function set dePhyWardProbAdd1(val:Number):void
		{
			_ui.labbel12.htmlText = StaticIni.getSwfLangStrVar("Pet_Property_09",[val.toFixed(2)]);
		}

	}
}